package collection;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test4 {
    @Test
    public void test() {
        Map<Integer, String> map = new HashMap<>();

        map.put(1, "CJ");
        map.put(3, "QQ");
        map.put(2, "CC");

//        System.out.println(map);
        // 遍历方法1
        Set<Integer> set = map.keySet();
        for (Integer integer : set) {
            System.out.println(integer + ": " + map.get(integer));
        }

        System.out.println("========================");

        // 遍历方法2
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }

    }
}
